import 'dart:ui';

import 'package:flutter/material.dart';

extension FWidgetExt on Widget {
  /// 添加背景色
  Widget fBgColor(Color color, [double radius = 0]) {
    return DecoratedBox(
      decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(radius)),
      child: this,
    );
  }

  /// 添加渐变背景
  Widget fHGradient(List<Color> colors, [double radius = 0]) {
    return DecoratedBox(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(radius),
        gradient: LinearGradient(
          begin: Alignment.centerLeft,
          end: Alignment.centerRight,
          colors: colors,
        ),
      ),
      child: this,
    );
  }

  /// 添加渐变背景
  Widget fVGradient(List<Color> colors, [double radius = 0]) {
    return DecoratedBox(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(radius),
        gradient: LinearGradient(
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
          colors: colors,
        ),
      ),
      child: this,
    );
  }

  /// 添加边框
  Widget fBorder([Color color = Colors.white, double width = 1.0, double radius = 0.0]) {
    return DecoratedBox(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(radius),
        border: Border.all(color: color, width: width),
      ),
      child: this,
    );
  }

  /// 添加阴影
  Widget fShadow({Color color = Colors.black12, double blurRadius = 10.0, Offset offset = const Offset(0, 2)}) {
    return DecoratedBox(
      decoration: BoxDecoration(
        boxShadow: [
          BoxShadow(
            color: color,
            blurRadius: blurRadius,
            offset: offset,
          ),
        ],
      ),
      child: this,
    );
  }

  /// 添加内边距
  Widget fPaddingOnly({double left = 0.0, double top = 0.0, double right = 0.0, double bottom = 0.0}) {
    return Padding(
      padding: EdgeInsets.only(left: left, top: top, right: right, bottom: bottom),
      child: this,
    );
  }

  /// 添加内边距
  Widget fPaddingSymmetric({double vertical = 0.0, double horizontal = 0.0}) {
    return Padding(
      padding: EdgeInsets.symmetric(vertical: vertical, horizontal: horizontal),
      child: this,
    );
  }

  /// 设置尺寸
  Widget fSize({double? width, double? height}) {
    return SizedBox(
      width: width,
      height: height,
      child: this,
    );
  }

  /// 设置宽高比
  Widget fAspectRatio(double aspectRatio) {
    return AspectRatio(
      aspectRatio: aspectRatio,
      child: this,
    );
  }

  /// 添加点击事件
  Widget fTap(VoidCallback onTap) {
    return GestureDetector(
      onTap: onTap,
      child: this,
    );
  }

  /// 居中对齐
  Widget fCenter() {
    return Center(child: this);
  }

  /// 自定义对齐
  Widget fAlign(Alignment alignment) {
    return Align(alignment: alignment, child: this);
  }

  /// 弹性布局 - Expanded
  Widget fExpanded([int flex = 1]) {
    return Expanded(flex: flex, child: this);
  }

  /// 弹性布局 - Flexible
  Widget fFlexible({int flex = 1, FlexFit fit = FlexFit.loose}) {
    return Flexible(flex: flex, fit: fit, child: this);
  }

  /// 圆角裁剪
  Widget fClipRRect([double radius = 8.0]) {
    return ClipRRect(
      borderRadius: BorderRadius.circular(radius),
      child: this,
    );
  }

  /// 设置透明度
  Widget fOpacity(double opacity) {
    return Opacity(opacity: opacity, child: this);
  }

  /// 模糊效果
  Widget fBlur([double sigma = 3.0]) {
    return ImageFiltered(
      imageFilter: ImageFilter.blur(sigmaX: sigma, sigmaY: sigma),
      child: this,
    );
  }

  /// 设置可见性
  Widget fVisible(bool visible) {
    return Visibility(visible: visible, child: this);
  }

  /// 旋转变换
  Widget fRotate(double angle) {
    return Transform.rotate(angle: angle, child: this);
  }

  /// 缩放变换
  Widget fScale(double scale) {
    return Transform.scale(scale: scale, child: this);
  }

  /// 平移变换
  Widget fTranslate(Offset offset) {
    return Transform.translate(offset: offset, child: this);
  }
}
